/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dbase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import model.*;
/**
 *
 * @author elfahruzzaman
 */
public class DBpengguna {
    Connection conn;

    public DBpengguna(Connection conn){
        this.conn = conn;
    }
public pengguna getUser(String username) {
        pengguna user = new pengguna();
        String sql = "SELECT * FROM pengguna WHERE username = ?";
        try {
            PreparedStatement st = this.conn.prepareStatement(sql);
            st.setString(1, username);
            ResultSet rs = st.executeQuery();
            if (rs != null) {
                if (rs.next()) {
                    user.setIdPengguna(rs.getInt(1));
                    user.setUsername(rs.getString(2));
                    user.setPassword(rs.getString(3));
                    user.setRole(rs.getString(4));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }

public anggota cekAnggota(String username) {
        anggota user = new anggota();
        String sql = "SELECT nrp FROM anggota WHERE nrp = ?";
        try {
            PreparedStatement st = this.conn.prepareStatement(sql);
            st.setString(1, username);
            ResultSet rs = st.executeQuery();
            if (rs != null) {
                if (rs.next()) {
                    user.setNrp(rs.getString(1));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }

public kendaraan cekKendaraanAnggota(String username) {
        kendaraan user = new kendaraan();
        String sql = "SELECT nrp FROM kendaraan WHERE nrp = ?";
        try {
            PreparedStatement st = this.conn.prepareStatement(sql);
            st.setString(1, username);
            ResultSet rs = st.executeQuery();
            if (rs != null) {
                if (rs.next()) {
                    user.setNrp(rs.getString(1));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }


}
